package cuit.epoch.pymjl.security.common.result;

import lombok.Data;

@Data
public class Result {
    private int code;//编码200/400
    private String msg;//成功、失败
    private Long total; //总记录数
    private Object data;//数据
    private String token;

    //成功
    public static Result suc() {
        return result(200, "成功", 0L, null);
    }

    public static Result suc02(Object data, String token) {
        return result02(200, "成功", data, token);
    }

    public static Result suc(Object data) {
        return result(200, "成功", 0L, data);
    }

    public static Result suc(Object data, Long total) {
        return result(200, "成功", total, data);
    }

    private static Result result(int code, String msg, Long total, Object data) {
        Result res = new Result();
        res.setData(data);
        res.setMsg(msg);
        res.setCode(code);
        res.setTotal(total);
        return res;
    }

    private static Result result02(int code, String msg, Object data, String token) {
        Result res = new Result();
        res.setData(data);
        res.setMsg(msg);
        res.setCode(code);
        res.setToken(token);
        return res;
    }

    public static Result fall(String msg) {
        return result(400, msg, 0L, null);
    }

    public static Result suc(String msg) {
        return result(200, msg, 0L, null);
    }
}
